<?php
/**
 * Atlas KOTASOFT cakephp
 *
 * Bakes web interface 
 *
 * PHP versions 4 and 5
 *
 * ATLAS KOTASOFT  cakephp web code generator
 * Copyright 2009, Kotasoft agile factory, Inc. (http://www.atlascakephp.com)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright     Copyright 2009, Kotasoft agile factory , Inc. (http://www.kotasoft.com)
 * @link          http://www.atlascakephp.com  ATLAS KOTASOFT Project
 * @version       BETA 0.5 $
 * @modifiedby    $LastChangedBy: daniel castanera - guldoe and francisco dominguez - idioto $
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 */



class KtAppController extends AppController {
	
 	var $helpers = array('Html', 'Form', 'Javascript');  
 	var $components = array('RequestHandler');  


	function listAll($useDbConfig = 'default', $interactive = true) {
		$db =& ConnectionManager::getDataSource($useDbConfig);
		$usePrefix = empty($db->config['prefix']) ? '' : $db->config['prefix'];
		if ($usePrefix) {
			$tables = array();
			foreach ($db->listSources() as $table) {
				if (!strncmp($table, $usePrefix, strlen($usePrefix))) {
					$tables[] = substr($table, strlen($usePrefix));
				}
			}
		} else {
			$tables = $db->listSources();
		}
		
		if (empty($tables)) {			 
			$this->Session->setFlash(__('Your database does not have any tables'));	
		}
				

		if (count($tables) > 0)
				return $tables; 			
		 
	}
	
	/* return fields bd */
	function __doFields(&$model, $interactive = true) {
		if (!is_object($model)) {
			return false;
		}
		$fields = $model->schema();
		return $fields;		
	}
	
	/* check that you haven been choose a configuration and you are login */
	function beforeFilter(){    	   	 
    	if (!$this->Session->check('User') && 
    		isset($this->params['prefix']) && 
    		$this->params['prefix']=='admin') {
				$this->checkAdminSession();
		}		
		$this->checkConfiguration();
    }
	
}
?>